home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWBmpShp.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  6.9 KB  |  244 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBmpShp.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWBMPSHP_H
  13. #include "FWBmpShp.h"
  14. #endif
  15.  
  16. #ifndef SLGRGLOB_H
  17. #include "SLGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef SLRENDER_H
  29. #include "SLRender.h"
  30. #endif
  31.  
  32. // ----- Foundation Includes -----
  33.  
  34. #ifndef FWSTREAM_H
  35. #include "FWStream.h"
  36. #endif
  37.  
  38. #ifndef FWDEBUG_H
  39. #include "FWDebug.h"
  40. #endif
  41.  
  42. //========================================================================================
  43. // File scope definitions
  44. //========================================================================================
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment fwgraphxshape
  48. #endif
  49.  
  50. //========================================================================================
  51. //    CLASS FW_CBitmapShape
  52. //========================================================================================
  53.  
  54. FW_DEFINE_CLASS_M1(FW_CBitmapShape, FW_CBoundedShape)
  55. FW_DEFINE_AUTO(FW_CBitmapShape)
  56.  
  57. // This class is archivable, but we provide the archiving implementation in a separate
  58. // translation unit in order to enable deadstripping of the archiving-related code
  59. // in parts that do not use archiving with this class.
  60.  
  61. //----------------------------------------------------------------------------------------
  62. //    FW_CBitmapShape::FW_CBitmapShape
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_CBitmapShape::FW_CBitmapShape(const FW_CBitmapShape& other) :
  66.     FW_CBoundedShape(other),
  67.     fSrcRect(other.fSrcRect),
  68.     fBitmap(other.fBitmap)
  69. {
  70.     FW_END_CONSTRUCTOR
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_CBitmapShape::FW_CBitmapShape
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_CBitmapShape::FW_CBitmapShape(FW_CBitmap bitmap, const FW_CRect& dstRect) :
  78.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  79.     fBitmap(bitmap)
  80. {
  81.     short width, height,rowBytes, pixelSize;
  82.     
  83.     fBitmap.GetBitmapInfo(width, height, rowBytes, pixelSize);
  84.     fSrcRect.SetInt(0, 0, width, height);
  85.  
  86.     FW_END_CONSTRUCTOR
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    FW_CBitmapShape::FW_CBitmapShape
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CBitmapShape::FW_CBitmapShape(FW_CBitmap bitmap, const FW_CRect& srcRect, const FW_CRect& dstRect) :
  94.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  95.     fSrcRect(srcRect),
  96.     fBitmap(bitmap)
  97. {
  98.     FW_END_CONSTRUCTOR
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_CBitmapShape::FW_CBitmapShape
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CBitmapShape::FW_CBitmapShape(FW_CReadableStream& stream) :
  106.     FW_CBoundedShape(stream)
  107. {
  108.     stream.Read(&fSrcRect, 4);
  109.     stream >> fBitmap;
  110.     
  111.     FW_END_CONSTRUCTOR
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CBitmapShape::~FW_CBitmapShape
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_CBitmapShape::~FW_CBitmapShape()
  119. {
  120.     FW_START_DESTRUCTOR
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CBitmapShape::operator=
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CBitmapShape& FW_CBitmapShape::operator=(const FW_CBitmapShape& other)
  128. {
  129.     if (this != &other)
  130.     {
  131.         FW_CBoundedShape::operator=(other);
  132.         
  133.         fBitmap = other.fBitmap;
  134.         fSrcRect = other.fSrcRect;
  135.     }
  136.     
  137.     return *this;
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CBitmapShape::Copy
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CShape* FW_CBitmapShape::Copy() const
  145. {
  146.     return FW_NEW(FW_CBitmapShape, (*this));
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    FW_CBitmapShape::Render
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void FW_CBitmapShape::Render(FW_CGraphicContext& gc) const
  154. {
  155.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  156.         gc,
  157.         fBitmap,
  158.         fSrcRect,
  159.         fRect,
  160.         GetRenderVerb(),
  161.         fInk);
  162.     FW_FailOnEvError(gc.GetEnvironment());
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CBitmapShape::RenderBitmap
  167. //----------------------------------------------------------------------------------------
  168.  
  169. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  170.                                     FW_CBitmap bitmap,
  171.                                     const FW_CRect& dstRect,
  172.                                     const FW_CInk& ink)
  173. {
  174.     FW_CRect srcRect;
  175.     bitmap.GetBitmapBounds(srcRect);
  176.  
  177.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  178.         gc,
  179.         bitmap,
  180.         srcRect,
  181.         dstRect,
  182.         FW_kFill,
  183.         ink);
  184.     FW_FailOnEvError(gc.GetEnvironment());
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    FW_CBitmapShape::RenderBitmap
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  192.                                     FW_CBitmap bitmap,
  193.                                     const FW_CRect& srcRect, 
  194.                                     const FW_CRect& dstRect,
  195.                                     const FW_CInk& ink)
  196. {
  197.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  198.         gc,
  199.         bitmap,
  200.         srcRect,
  201.         dstRect,
  202.         FW_kFill,
  203.         ink);
  204.     FW_FailOnEvError(gc.GetEnvironment());
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    FW_CBitmapShape::GetGeometry
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void FW_CBitmapShape::GetGeometry(FW_CBitmap& bitmap, 
  212.                                 FW_CRect& srcRect, 
  213.                                 FW_CRect& dstRect) const
  214. {
  215.     bitmap = fBitmap;
  216.     srcRect = fSrcRect;
  217.     dstRect = fRect;
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    FW_CBitmapShape::SetGeometry
  222. //----------------------------------------------------------------------------------------
  223.  
  224. void FW_CBitmapShape::SetGeometry(const FW_CBitmap& bitmap, 
  225.                                 const FW_CRect& srcRect, 
  226.                                 const FW_CRect& dstRect)
  227. {
  228.     fBitmap = bitmap;
  229.     fSrcRect = srcRect;
  230.     fRect = dstRect;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_CBitmapShape::Flatten
  235. //----------------------------------------------------------------------------------------
  236.  
  237. void FW_CBitmapShape::Flatten(FW_CWritableStream& stream) const
  238. {
  239.     FW_CBoundedShape::Flatten(stream);
  240.     stream.Write(&fSrcRect, 4);
  241.     stream << fBitmap;
  242. }
  243.  
  244.